<?php 
namespace app\model;

use think\Model;
use think\Db;

class Category extends Model{
	public static function getListByPage($num){
		$res = Db::name('category ca')
				->field("ca.category_id,category_name,ca.is_delete,count(commodity_id) as num")
				->join("commodity co","ca.category_id = co.category_id and co.is_delete=0","LEFT")
				->group('ca.category_id')
				->select();
		return $res;
	}

	public static function getCommodityNum($category_id){
		$res = Db::name('commodity')
				->field("count(commodity_id) num")
				->where("category_id",$category_id)
				->select();
		return $res[0]["num"];
	} 
}

 ?>